package com.lovo.project.servlet.service;

import com.lovo.project.enums.ServiceCodeEnum;
import com.lovo.project.exception.OurException;
import com.lovo.project.model.ServiceDO;
import com.lovo.project.service.ServiceService;
import com.lovo.project.service.impl.ServiceServiceImpl;
import com.lovo.project.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author dell
 */
@WebServlet(name = "InsertServiceServlet",value = "/service/insertService")
public class InsertServiceServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO: 2020/11/4 15:45 段可帅 服务添加书写查询字段
            try {
                String serviceName = request.getParameter("serviceName");
                String serviceClass = request.getParameter("serviceClass");
                String serviceCuttingSpecification = request.getParameter("serviceCuttingSpecification");
                String serviceTimeConsuming = request.getParameter("serviceTimeConsuming");
                String serviceEmployGrade = request.getParameter("serviceEmployGrade");
                Integer shopId = Integer.parseInt(request.getParameter("shopId"));
                
                Integer serviceMoney = Integer.parseInt(request.getParameter("serviceMoney"));
                String serviceSchedule = request.getParameter("serviceSchedule");
                String serviceSpecification = request.getParameter("serviceSpecification");
                ServiceDO serviceDO =new ServiceDO();
                
                serviceDO.setServiceName(serviceName);
                serviceDO.setServiceClass(serviceClass);
                serviceDO.setServiceCuttingSpecification(serviceCuttingSpecification);
                serviceDO.setServiceSpecification(serviceSpecification);
                serviceDO.setServiceTimeConsuming(serviceTimeConsuming);
                serviceDO.setServiceEmployGrade(serviceEmployGrade);
                serviceDO.setServiceMoney(serviceMoney);
                serviceDO.setServiceSchedule(serviceSchedule);
                serviceDO.setShopId(shopId);
                ServiceService serviceService = new ServiceServiceImpl();
                Integer integer = serviceService.insertService(serviceDO);
                response.getWriter().print(ResultVO.success().add(integer).toJson());


            }catch (OurException e){
                response.getWriter().print(ResultVO.fail(e.getCodeEnum()).toJson());
            }catch (Exception e1){
                response.getWriter().print(ResultVO.fail(ServiceCodeEnum.SERVICE_UNKNOWN_ERROR).toJson());
            }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
